<!-- 新增/重命名流程 -->
<template>
  <dt-modal-edit ref='edit' :title='title' :label-width='130' :width='800' @ok='onOk'
    :okText='okText' :cancelText='cancelText'>
  </dt-modal-edit>
</template>

<script>
  import editOpt from '../opt/edit.js'
  import processApi from '@/biz/flowApproval/processManagement'
  export default {
    data() {
      return {
        info: {},
        title: '新增/重命名流程',
        okText: '保存',
        cancelText: '关闭',
        flag: 'create'
      }
    },
    mounted() {},
    methods: {
      create() {
        this.flag = 'create'
        this.title = '新增流程'
        this.info = {
          processName: '',
        }
        this.show()
      },
      edit(info) {
        console.log(info)
        this.flag = 'edit'
        this.title = '重命名流程'
        this.info = info
        console.log(this.info)
        this.show()
      },
      show() {
        this.$refs.edit.show(editOpt.options(this), this.info)
      },
      hide() {
        this.$refs.edit.hide()
      },
      onOk() {
        console.log(this.info)
        let params = {
          ...this.info
        }
        if (this.flag == 'create') {
          processApi.processSave(params)
            .then((res) => {
              console.log(res)
              this.$emit('success', 'create')
              this.hide()
            })
        } else if (this.flag == 'edit') {
          processApi.processUpdate(params)
            .then((res) => {
              this.$emit('success', this.info.id)
              this.hide()
            })
        }

      },
    },
  }
</script>

<style>
</style>